home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / pronunciation_dict.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.0 KB  |  59 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Exposes a dictionary, pronunciation_dict, that maps words to what
  5. they sound like.'''
  6. __id__ = '$Id: pronunciation_dict.py 3882 2008-05-07 18:22:10Z richb $'
  7. __version__ = '$Revision: 3882 $'
  8. __date__ = '$Date: 2008-05-07 14:22:10 -0400 (Wed, 07 May 2008) $'
  9. __copyright__ = 'Copyright (c) 2006-2008 Sun Microsystems Inc.'
  10. __license__ = 'LGPL'
  11.  
  12. def getPronunciation(word, pronunciations = None):
  13.     '''Given a word, return a string that represents what this word
  14.     sounds like.
  15.  
  16.     Arguments:
  17.     - word: the word to get the "sounds like" representation for.
  18.     - pronunciations: an optional dictionary used to get the pronunciation
  19.       from.
  20.  
  21.     Returns a string that represents what this word sounds like, or 
  22.     the word if there is no representation.
  23.     '''
  24.     if isinstance(word, unicode):
  25.         word = word.encode('UTF-8')
  26.     
  27.     
  28.     try:
  29.         lowerWord = word.decode('UTF-8').lower().encode('UTF-8')
  30.         if pronunciations != None:
  31.             return pronunciations[lowerWord][1]
  32.         return pronunciation_dict[lowerWord][1]
  33.     except:
  34.         return word
  35.  
  36.  
  37.  
  38. def setPronunciation(word, replacementString, pronunciations = None):
  39.     '''Given an actual word, and a replacement string, set a key/value
  40.     pair in a pronunciation dictionary.
  41.  
  42.     Arguments:
  43.     - word: the word to be pronunced.
  44.     - replacementString: the replacement string to use instead.
  45.     - pronunciations: an optional dictionary used to set the pronunciation
  46.       into.
  47.     '''
  48.     key = word.decode('UTF-8').lower().encode('UTF-8')
  49.     if pronunciations != None:
  50.         pronunciations[key] = [
  51.             word,
  52.             replacementString]
  53.     else:
  54.         pronunciation_dict[key] = [
  55.             word,
  56.             replacementString]
  57.  
  58. pronunciation_dict = { }
  59.